$spriteSrc:'/images/coupons.png';

$spriteWidth: 407px;
$spriteHeight: 398px;
$coupon-gary: 0px 0px 252px 66px;
$coupon-gray-left: -349px 0px 25px 158px;
$coupon-gray-right: 0px -245px 17px 153px;
$coupon-red-left: -382px 0px 25px 158px;
$coupon-red-right: -25px -245px 17px 153px;
$coupon-red: 0px -74px 252px 66px;
$gift-gray: 0px -148px 79px 89px;
$gift-red: -87px -148px 79px 89px;
$not-active: -260px 0px 81px 81px;

@function px2rem ($px) {
  @if (type-of($px) == "number") {
    @return $px / 20px * 1rem;
  }
  @if (type-of($px) == "list") {
    @if (nth($px, 1) == 0 and nth($px, 2) != 0) {
      @return 0 nth($px, 2) / 20px * 1rem;
    } @else if (nth($px, 1) == 0 and nth($px, 2) == 0)  {
      @return 0 0;
    } @else if (nth($px, 1) != 0 and nth($px, 2) == 0) {
      @return nth($px, 1) / 20px * 1rem 0;
    } @else {
      @return nth($px, 1) / 20px *1rem nth($px, 2) / 20px * 1rem;
    }
  }
}

@mixin sprite-width($sprite) {
	width: px2rem(nth($sprite, 3));
}

@mixin sprite-height($sprite) {
	height: px2rem(nth($sprite, 4));
}

@mixin sprite-position($sprite) {
	$sprite-offset-x: px2rem(nth($sprite, 1));
	$sprite-offset-y: px2rem(nth($sprite, 2));
	background-position: $sprite-offset-x  $sprite-offset-y;
}

@mixin sprite($sprite) {
	@include sprite-position($sprite);
	@include sprite-width($sprite);
	@include sprite-height($sprite);
    background-image: url('#{$spriteSrc}');
	background-repeat: no-repeat;
	background-size: px2rem(($spriteWidth, $spriteHeight));
    display: inline-block;
}


@mixin mix-coupon-gary() {
    @include sprite($coupon-gary);
}
@mixin mix-coupon-gray-left() {
    @include sprite($coupon-gray-left);
}
@mixin mix-coupon-gray-right() {
    @include sprite($coupon-gray-right);
}
@mixin mix-coupon-red-left() {
    @include sprite($coupon-red-left);
}
@mixin mix-coupon-red-right() {
    @include sprite($coupon-red-right);
}
@mixin mix-coupon-red() {
    @include sprite($coupon-red);
}
@mixin mix-gift-gray() {
    @include sprite($gift-gray);
}
@mixin mix-gift-red() {
    @include sprite($gift-red);
}
@mixin mix-not-active() {
    @include sprite($not-active);
}
